home *** CD-ROM | disk | FTP | other *** search
- Path: inforamp.net!ts31-02
- From: rmorin@inforamp.net (Randy Charles Morin)
- Newsgroups: comp.lang.c++
- Subject: Re: How can I include IOSTREAM.H only once?
- Date: Mon, 11 Mar 96 06:05:40 GMT
- Organization: MiddleWorld SoftWare
- Message-ID: <4i0fs4$5g9@sam.inforamp.net>
- References: <4hbi55$899@sam.inforamp.net> <4hc09v$136@news1.usa.pipeline.com> <4hj42l$elu@sam.inforamp.net> <4hqck8$fvc@uuneo.neosoft.com> <4hsgid$pmm@sam.inforamp.net> <4htg6a$593@news4.digex.net>
- NNTP-Posting-Host: ts31-02.tor.inforamp.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4htg6a$593@news4.digex.net>, ell@access1.digex.net (Ell) wrote:
- >Randy Charles Morin (rmorin@inforamp.net) wrote:
- >: >#ifndef __STDIO__
- >: >#include <stdio.h>
- >: >#endif
- >
- >And generally the '#endif' is the last of code in the file.
- >#ifndef __STDIO__
- >#include <stdio.h>
- > /*...code...*/
- > /*...code...*/
- >#endif
-
- Sorry, but this is wrong. Everybody, including myself is almost always
- wrong, so let's not belabor the point. What I was attempting to do is include
- a file only if it has not already been included. Surely the file <stdio.h>
- has simliar pre-compile statements to what you describe, but the include file
- will still be loaded during pre-compilation without using the pre-compile
- statements I describe. My statement load the file only if they have not
- been pre-loaded, as oppose to the other statements compiling the file only if
- they have not been previously compiled.
-
- Example:
-
- header.h
- --------
- #ifndef HEADER_H
- #define HEADER_H
- typedef bool int;
- #endif
- ------
-
- source.cpp
- ----------
- #ifndef HEADER_H
- #include "header.h"
- #endif
- #ifndef HEADER_H
- #include "header.h"
- #endif
- int main()
- {
- bool b;
- int i=0;
- b=i;
- return b;
- };
- -----
-
- source2.cpp
- ----------
- #include "header.h"
- #include "header.h"
- int main()
- {
- bool b;
- int i=0;
- b=i;
- return b;
- };
- -----
-
- source.cpp will compile faster then source2.cpp because the first source loads
- the header file once, while the second source loads the header file twice.
- This is a simply example and no noticeable compile time savings will occur.
- But if all standard headers used this type of syntax, then compile times would
- greatly increase.
-
- Agrivar
-